var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2AudioManager = require("AudioManager");
var $2BulletMgr = require("BulletMgr");
var $2BundleManager = require("BundleManager");
var $2ZombieMgr = require("ZombieMgr");
var $2SceneStage = require("SceneStage");
var $2KDefine = require("KDefine");
var $2MyUtils = require("MyUtils");
var $2BulletBase = require("BulletBase");
var $2PlantBase = require("PlantBase");
var g = cc._decorator.ccclass;
var def_Plant5 = /* */function (_u$default2) {
  babel_inherits(p, _u$default2);
  var _super68 = babel_createSuper(p);
  function p() {
    var _this147;
    babel_classCallCheck(this, p);
    _this147 = _super68.apply(this, arguments);
    _this147.attackType = 0;
    return _this147;
  }
  babel_createClass(p, [{
    key: "shoot",
    value: function shoot() {
      var _this148 = this;
      var e = this;
      var t = this.getZombie();
      if (null != t) {
        if (0 == this.remainCD) {
          var _a35 = this.dragon.setAnimation(0, "dazhao", false);
          this.dragon.setCompleteListener(function () {
            e.setState($2KDefine.State.wait);
            _this148.attackTimes += _this148.attackCD;
            _this148.remainCD = _this148.skillCD;
          });
          this.dragon.setTrackEventListener(_a35, function (e, a) {
            "dazhao" == a.data.name && _this148.attack(t, true);
          });
        } else {
          this.dragon.setCompleteListener(function () {
            e.setState($2KDefine.State.wait);
          });
          this.attackTimes += this.attackCD;
          var _a36 = this.dragon.setAnimation(0, "gongji", false);
          this.dragon.setTrackEventListener(_a36, function (e, a) {
            "gongji" == a.data.name && _this148.attack(t);
          });
        }
      } else {
        e.setState($2KDefine.State.wait);
      }
    }
  }, {
    key: "stateWait",
    value: function stateWait(e) {
      if (this.state === $2KDefine.State.wait) {
        this.state = $2KDefine.State.waiting;
        this.dragon.setAnimation(0, "daiji", true);
        this.dragon.setCompleteListener(null);
      }
      this.pTime += e;
      if (this.pTime > this.checkTargetTime && !this.isPause) {
        this.pTime = 0;
        this.attackTimes <= 0 && this.checkTarget() && this.setState($2KDefine.State.attack);
      }
    }
  }, {
    key: "attack",
    value: function attack(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
      var a;
      var n;
      var l;
      var d = this.attackType;
      var u = new cc.Vec2(this.node.getPosition().x + this.shootPo.x, this.node.getPosition().y + this.shootPo.y);
      var g = new cc.Vec2(u.x + (e.x - u.x) / 2, u.y + 400);
      if (t) {
        $2AudioManager.default.instance.playEffect(this.skillSound, this.skillSoundVolume);
        a = $2BulletMgr.default.instance().getItem(this.skillbullet, this.damage, this.hitSound, this.hitSoundVolume).node;
      } else {
        $2AudioManager.default.instance.playEffect(this.shootSound, this.shootSoundVolume);
        a = 0 == d ? $2BulletMgr.default.instance().getItem(this.bulletId, this.damage, this.hitSound, this.hitSoundVolume).node : $2BulletMgr.default.instance().getItem(25, this.damage, this.hitSound, this.hitSoundVolume).node;
      }
      if (t) {
        n = Math.atan2(g.y - u.y, g.x - u.x) * (180 / Math.PI);
        l = Math.atan2(e.y - g.y, e.x - g.x) * (180 / Math.PI);
      } else {
        n = 30;
        l = 720;
      }
      a.angle = n;
      a.getComponent(cc.CircleCollider).enabled = false;
      a.parent = $2SceneStage.default.instance.groudNode;
      a.setPosition(u);
      a.zIndex = $2KDefine.ZIndex.bullet;
      a.opacity = 255;
      cc.tween(a).parallel(cc.tween(a).bezierTo(1.5 / this.attackSpeed, u, g, e), cc.tween(a).to(1.5 / this.attackSpeed, {
        angle: l
      })).call(function () {
        a.getComponent(cc.CircleCollider).enabled = true;
        a.getChildByName("bulletEffect").active = true;
        a.getComponent(cc.Sprite).enabled = false;
        var e = a.getChildByName("bulletEffect").getComponent(sp.Skeleton);
        e.skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "effect/" + a.getComponent($2BulletBase.default).bulletEffect + "/" + a.getComponent($2BulletBase.default).bulletEffect, sp.SkeletonData);
        e.setAnimation(0, "newAnimation", false);
        e.setCompleteListener(function () {
          a.getChildByName("bulletEffect").active = false;
          $2BulletMgr.default.instance().removeBullet(a.getComponent($2BulletBase.default));
          e.setCompleteListener(null);
        });
      }).start();
    }
  }, {
    key: "getZombie",
    value: function getZombie() {
      var _this149 = this;
      var e = 99999;
      var t = null;
      $2ZombieMgr.default.instance().zombieInRow[this.row].forEach(function (a) {
        if (_this149.node.x < a.node.x) {
          var _n35 = $2MyUtils.MyUtils.getDis(_this149.node.x, _this149.node.y, a.node.x, a.node.y);
          if (_n35 < e) {
            e = _n35;
            t = a.node;
          }
        }
      });
      if (null == t) {
        return null;
      } else {
        return new cc.Vec2(t.getPosition().x - 25, t.getPosition().y);
      }
    }
  }]);
  return p;
}($2PlantBase.default);
def_Plant5 = cc__decorate([g], def_Plant5);
exports.default = def_Plant5;